package cn.edu.scau.cmi.ema.domain;


import com.alibaba.fastjson.annotation.JSONField;

import javax.persistence.*;
import javax.xml.bind.annotation.*;
import java.io.Serializable;
import java.math.BigDecimal;

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllFillerhazards", query = "select myFillerhazard from Fillerhazard myFillerhazard"),
		@NamedQuery(name = "findFillerhazardByName", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.name = ?1"),
		@NamedQuery(name = "findFillerhazardByNameContaining", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.name like concat('%',?1,'%')"),
		@NamedQuery(name = "findFillerhazardByMin", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.min = ?1"),
		@NamedQuery(name = "findFillerhazardByMax", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.max = ?1"),
		@NamedQuery(name = "findFillerhazardByDegree", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.degree = ?1"),
		@NamedQuery(name = "findFillerhazardByDegreeContaining", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.degree like concat('%',?1,'%')"),
		@NamedQuery(name = "findFillerhazardByDescription", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.description = ?1"),
		@NamedQuery(name = "findFillerhazardByDescriptionContaining", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.description like concat('%',?1,'%')"),
		@NamedQuery(name = "findAllFillerhazardsByFiller", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.filler.id = ?1"),
		@NamedQuery(name = "findAllFillerhazardsByHazard", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.hazard.id = ?1"),
		@NamedQuery(name = "findFillerhazardById", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.id = ?1"),
		@NamedQuery(name = "findFillerhazardByPrimaryKey", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.id = ?1 "),
		@NamedQuery(name = "deleteFillerhazardsByIds", query = "delete Fillerhazard where id in (?1)"),
		@NamedQuery(name = "findFillerhazardsByIds", query = "select myFillerhazard from Fillerhazard myFillerhazard where myFillerhazard.id in (?1)"),
		@NamedQuery(name = "findFillerhazardByPhyscialPrimaryKey", query = "select myFillerhazard from Fillerhazard myFillerhazard where  myFillerhazard.filler.id = ?1 and myFillerhazard.hazard.id = ?2 and myFillerhazard.degree = ?3"),
		@NamedQuery(name = "countFillerhazardsByName", query = "select count(myFillerhazard)  from Fillerhazard myFillerhazard where myFillerhazard.name like concat('%',?1,'%')") })
@Table(catalog = "ema", name = "fillerhazard")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "ema/cn/edu/scau/cmi/ema/domain", name = "Fillerhazard")
@XmlRootElement(namespace = "ema/cn/edu/scau/cmi/ema/domain")

public class Fillerhazard implements Serializable, Comparable<Fillerhazard> {

	private static final long serialVersionUID = 1L;

	@Column(name = "id", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@XmlElement
	Integer id;

	@Column(name = "name")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String name;

	@Column(name = "min", precision = 22)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	BigDecimal min;

	@Column(name = "max", precision = 22)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	BigDecimal max;

	@Column(name = "degree")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String degree;

	@Column(name = "description")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String description;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "filler", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Filler filler;
	@JSONField(serialize = false)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "hazard", referencedColumnName = "id", nullable = false) })
	@XmlTransient
	Hazard hazard;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return this.id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public void setMin(BigDecimal min) {
		this.min = min;
	}

	public BigDecimal getMin() {
		return this.min;
	}

	public void setMax(BigDecimal max) {
		this.max = max;
	}

	public BigDecimal getMax() {
		return this.max;
	}

	public void setDegree(String degree) {
		this.degree = degree;
	}

	public String getDegree() {
		return this.degree;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return this.description;
	}

	public void setFiller(Filler filler) {
		this.filler = filler;
	}

	public Filler getFiller() {
		return filler;
	}

	public void setHazard(Hazard hazard) {
		this.hazard = hazard;
	}

	public Hazard getHazard() {
		return hazard;
	}

	public void copy(Fillerhazard that) {

		setId(that.getId());

		setName(that.getName());
		setMin(that.getMin());
		setMax(that.getMax());
		setDegree(that.getDegree());
		setDescription(that.getDescription());

		setFiller(that.getFiller());

		setHazard(that.getHazard());

	}

	public Fillerhazard() {

	}

	@Override
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");

		buffer.append("name=[").append(name).append("] ");
		buffer.append("min=[").append(min).append("] ");
		buffer.append("max=[").append(max).append("] ");
		buffer.append("degree=[").append(degree).append("] ");
		buffer.append("description=[").append(description).append("] ");

		return buffer.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Fillerhazard))
			return false;
		Fillerhazard comparedFillerhazard = (Fillerhazard) obj;
		if (!CheckPropertyEqual(this.filler.id, comparedFillerhazard.filler.id)) {
			return false;
		}
		if (!CheckPropertyEqual(this.hazard.id, comparedFillerhazard.hazard.id)) {
			return false;
		}
		if (!CheckPropertyEqual(this.degree, comparedFillerhazard.degree)) {
			return false;
		}
		return true;
	}

	public static <T> boolean CheckPropertyEqual(T originProperty, T comparedProperty) {
		// 基本类型经过参数传递后会自动装箱
		String[] className = originProperty.getClass().getName().split("\\.");
		if (className[0].equals("java") && className[1].equals("math")) {
			return ((Comparable) originProperty).compareTo(comparedProperty) == 0 ? true : false;
		} else {
			return originProperty.equals(comparedProperty);
		}
	}

	@Override
	public int compareTo(Fillerhazard o) {
		if (this.getId() > o.getId()) {
			return 1;
		} else if (this.getId() == o.getId()) {
			return 0;
		} else {
			return -1;
		}

	}
}
